//Copyright 2010 Balazs Keri, Imre Keri
//
//This file is part of FireworksCreator.
//
//FireworksCreator is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//FireworksCreator is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with FireworksCreator.  If not, see <http://www.gnu.org/licenses/>.
//
#ifndef _MODELDATAOBJECTADAPTER_H
#define _MODELDATAOBJECTADAPTER_H
//
#include <global.h>
#include <QString>
#include <QIcon>
#include <QHash>
#include <QVariant>
#include <common/iddictionary.h>
#include <common/identified_fwd.h>
#include <common/restoreerror_fwd.h>
#include <model/root_fwd.h>
#include <model/particletemplate_fwd.h>
#include <model/emittertemplate_fwd.h>
//
class Document;
class MainView;
class ModelGroupAdapter;
class ModelShooterAdapter;
class ModelParticleTemplateAdapter;
class ModelEmitterTemplateAdapter;
class ObjectPage;
class UiError;
class ModelDataObjectAdapter{
   Q_DISABLE_COPY(ModelDataObjectAdapter)
//initializer
public:
   class Initializer{
   public:
      Initializer();
      ~Initializer();
   private:
      Initializer(const Initializer&);
      Initializer &operator=(const Initializer&);
   };
   friend class Initializer;
//predefined objects
private:
   static ModelGroupAdapter *group_adapter;
   static ModelShooterAdapter *shooter_adapter;
   static ModelParticleTemplateAdapter *particle_template_adapter;
   static ModelEmitterTemplateAdapter *emitter_template_adapter;
public:
   static ModelGroupAdapter &get_group_adapter();
   static ModelShooterAdapter &get_shooter_adapter();
   static ModelParticleTemplateAdapter &get_particle_template_adapter();
   static ModelEmitterTemplateAdapter &get_emitter_template_adapter();
   static ModelDataObjectAdapter *get_adapter(unsigned int type);
   static ModelDataObjectAdapter *get_adapter(const QString &class_name);
//interface for users
public:
   virtual Identified *create_object(QObject* p_parent) const = 0;
   virtual QString get_object_name(const Identified *p_object) const = 0;
   virtual void set_object_name(Identified *p_object,QString p_name) const = 0;
   virtual void insert_into_root(Identified *p_object, model::Root *p_root) const = 0;
   virtual void remove_from_root(Identified *p_object, model::Root *p_root) const = 0;
   virtual void store_object_data(const Identified *p_object, QByteArray &p_bytes) const = 0;
   virtual Identified *restore_object(const QByteArray &p_bytes, const IdDictionary &p_dictionary) const  = 0;
   virtual unsigned int get_adapter_type() const = 0;
   virtual QString get_type_name() const = 0;
   virtual QIcon get_type_icon() const = 0;
   virtual QString get_short_name() const = 0;
   virtual ObjectPage *create_page(MainView *p_main_view,QWidget *p_parent) const = 0;
protected:
   ModelDataObjectAdapter();
   ~ModelDataObjectAdapter();
//types
public:
   static unsigned int get_type(const QString &class_name);
protected:
   enum Types {
      type_invalid,
      type_group_adapter,
      type_shooter_adapter,
      type_particle_template_adapter,
      type_emitter_template_adapter
   };
   static QHash<QString,unsigned int> name_to_type;
private:
   static void initialize_name_to_type();
//constants
protected:
   static const qint32 data_version_1_qt_4_6;
//initialize
private:
   static Initializer initializer;
};
//
#endif
